<?php

class ContatoController extends Site_Controller_Action
{

    public function init()
    {
        
    } 

    public function indexAction()
    {
        $this->view->headScript()->appendFile($this->_urlbase.'/public/media/js/validation/dist/jquery.validate.min.js');
        $this->view->headScript()->appendFile($this->_urlbase.'/public/media/js/view/contato.js');
        $this->view->headScript()->appendFile($this->_urlbase.'/public/media/js/jquery.maskedinput.min.js');
        
        $this->view->submenu_page = TRUE;
        
        $form = new Application_Form_Contato();
        
        $this->view->form = $form;
        if ($this->getRequest()->isPost()) {
            $formData = $this->getRequest()->getPost();
            if ($form->isValid($formData)) {
                
                Zend_Loader::loadClass('envioemail','library');
                $ok = envioemail::formularioContato($form);
                
                if($ok){
                    $form->reset();
                    $this->view->retorno = "<script>alert('Mensagem enviada com sucesso!');</script>";
                }
            }
        }
        
    }
    /*
    public function enviarAction()
    {
        $this->_helper->layout->disableLayout(); 
        $this->_helper->viewRenderer->setNoRender(); 
        
        $body = '<strong>Contato Site</strong></br></br>';
        $body.= '<p> Nome: '.$this->_getParam('nome').'</p>';
        $body.= '<p> Email: '.$this->_getParam('email').'</p>';
        $body.= '<p> Assunto: '.$this->_getParam('assunto').'</p>';
        $body.= '<p> Mensagem: '.$this->_getParam('mensagem').'</p>';
        
        
        $mail = new Zend_Mail();
        $mail->setBodyText($body);
        $mail->setFrom($this->_getParam('email'),$this->_getParam('nome'));
        $mail->addTo('alenkar.k@gmail.com');
        $mail->setSubject($this->_getParam('assunto'));
        $ok = $mail->send();
    
        echo json_encode(array('ok' => $ok));
    }
    */

}

